<!DOCTYPE html>
<html lang="en" xmlns:layout="http://www.w3.org/1999/xhtml"
      layout:decorate="~{admin/adminJs}" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-model="http://www.w3.org/1999/xhtml">
<body layout:fragment="content">
<div id="from">
    <el-form label-width="100px" :model="menu"  ref="menu" :rules="rules"  style="padding: 15px;">
        <el-form-item label="菜单名称:" prop="name">
            <el-input v-model="menu.name" style="width: 90%;"></el-input>
        </el-form-item>
        <el-form-item label="一级菜单:" v-if="menu.pid!='0'">
            <el-input v-model="menu.pidName" style="width: 90%;" readonly></el-input>
        </el-form-item>
        <el-form-item label="链接地址:" prop="url">
            <el-input v-model="menu.url" style="width: 90%;"></el-input>
        </el-form-item>
        <el-form-item label="是否显示:" prop="isDisplay">
            <el-input v-model="menu.isDisplay" style="width: 90%;"></el-input>
        </el-form-item>
        <el-form-item label="排序:" prop="orderNo">
            <el-input-number  v-bind:controls="false"  v-model="menu.orderNo" style="width: 90%;"></el-input-number>
        </el-form-item>
        <el-form-item label="描述:" prop="description">
            <el-input v-model="menu.description" type="textarea" style="width: 90%;"></el-input>
        </el-form-item>
        <el-row style="text-align: center">
            <el-button type="primary" @click="onSubmit">保存</el-button>
            <el-button @click="resetForm('menu')">重置</el-button>
            <el-button @click="cancel()">取消</el-button>
        </el-row>
    </el-form>
</div>
<script>

    var id=RequestUtils.getId();
    var pid=RequestUtils.get('pid');
    var pidName=RequestUtils.get('pidName');

    var vm=new Vue({
        el: '#from',
        data:function () {
            var menu=ajaxGet("/admin/system/menu/read",{id:id});
            menu.pid=pid;
            menu.pidName=pidName;
            delete menu.children;
            var rules={
                pid:ValidateUtils.required('请输入父节点ID!'),
                name:ValidateUtils.required('请输入菜单名称!'),
                description:ValidateUtils.required('请输入描述!'),
                isDisplay:ValidateUtils.required('请输入是否显示!'),
                url:ValidateUtils.required('请输入链接地址!'),
                orderNo:ValidateUtils.required('请输入排序!')
            };
            return {
                menu:menu,
                rules:rules
            };
        },
        methods:{
            onSubmit:function () {
                this.$refs['menu'].validate(function(valid) {
                    if (valid) {
                        EasyuiUtils.confirmSave("/admin/system/menu/save",vm.menu,function () {
                            vm.closeParentDialog(true);
                        });
                    } else {
                       EasyuiUtils.alert('请输入必填项!');
                    }
                });

            },
            cancel:function () {
                vm.closeParentDialog();
            },
            closeParentDialog:function(isRefresh){
                if(pid=="0" && isRefresh){
                    window.parent.reloadTree(isRefresh); //刷新树
                }
                window.parent.closeDialog(isRefresh);
            },
            resetForm:function(formName) {
                this.$refs[formName].resetFields();
            }
        }
    });
</script>

</body>
</html>